import { useState, useEffect } from 'react'
import FetchHelper from '../../../../../../../utils/helper/fetch-helper'
import { Table } from 'antd'
import _ from 'lodash'
export default function RainTable(props) {
    const [datas, setDatas] = useState([]);
    useEffect(() => {
        FetchHelper.getJson(`/admin-api/ybyj/rysdsc/list`, {
            // ...params,
            // qx,
            pageSize: 100,
            type: '降雨量'
        }).then(resp => {
            console.log('aa', resp)
            setDatas(resp.rows)
        })
    }, [])

    const groupDatas = _.groupBy(datas, 'qx')
    const dataSource = _.keys(groupDatas).map(key => {
        const lastData = _.maxBy(groupDatas[key], 'tm')
        return {
            name: key,
            time: lastData.tm,
            data: lastData.data
        }
    })

    return <>
        <Table columns={[{
            title: '区域',
            dataIndex: 'name'
        }, {
            title: '时间',
            dataIndex: 'time'
        }, {
            title: '降雨量',
            dataIndex: 'data'
        }]} dataSource={dataSource} bordered pagination={false} size="middle"></Table>
    </>;
}